<?php
	require_once("../process/connect_db.php");

	class session{
		
		var $db, $query, $db_torneig;

		public function __construct(){
			$db = new bd("admins");
		
			$res = null;
			session_start();
			
					foreach ($_SESSION as $key => $value) {
		     echo $key. "->".$value;	
		}
			
			if(isset($_SESSION['cookies'])){
				$query="Select * From admins";
				$res = $db->consulta($query);
				
				$trobat = false;
				for ($i=0; $i < sizeof($res) and !$trobat; $i++) { 
					if($res[$i]['session'] == $_SESSION['cookies']){
						$trobat = true;
						$_SESSION['torneig'] = $res[$i]['nom_torneig'];
					}
				}
				
				if(!$trobat){
					header("location: ../forms/f_autent.php");
				}
			} else {
				header("location: ../forms/f_autent.php");
			}
		
			$this->db = new bd('admins');
			$this->query = "Select nom_db From admins Where nom_torneig = \"". $_SESSION['torneig']. "\"";
			$this->db_torneig = $db->consulta($query);	
		}

		public function getDB_torneig(){
			return new bd($this->db_torneig[0]['nom_db']);
		}
	};


	
?>